package com.ruoyi.web.controller.bi.model;

import com.alibaba.fastjson.JSONObject;
import com.rsbi.ext.engine.view.context.grid.PageInfo;
import com.ruoyi.bi.domain.common.PageParam;
import com.ruoyi.bi.domain.common.Result;
import com.ruoyi.bi.domain.model.Cube;
import com.ruoyi.bi.service.model.CubeService;
import com.ruoyi.bi.util.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 */
@RestController
@RequestMapping(value = "/model")
public class CubeController extends BaseController {

	@Autowired
	private CubeService cubeService;

	@GetMapping("/listCube")
	public AjaxResult list(){
		return AjaxResult.success(cubeService.list());
	}

	@RequestMapping(value="/pageCube")
	public AjaxResult page(@RequestParam String key,@RequestParam PageParam page){
//		PageHelper.startPage(page.getPage(), page.getRows());
//		List<Cube> ls = cubeService.listCube(key);
//		PageInfo<Cube> pageInfo=new PageInfo<Cube>(ls);
		return AjaxResult.success();
	}

	@PostMapping("/saveCube")
	public AjaxResult saveCube(@RequestBody Cube cube){
		return cubeService.insertCube(cube);
	}

	@PutMapping("/updateCube")
	public AjaxResult updateCube(@RequestBody Cube cube){
		Result ret = cubeService.updateCube(cube);
		return AjaxResult.success(ret);
	}

	@DeleteMapping("/delCube/{cubeId}")
	public AjaxResult delCube(@PathVariable Integer cubeId){
		Result ret = cubeService.deleteCube(cubeId);
		return AjaxResult.success(ret);
	}

	@GetMapping(value="/getCube")
	public AjaxResult getCube(@RequestParam Integer cubeId){
		JSONObject cube = cubeService.getCubeById(cubeId);
		return AjaxResult.success(cube);
	}

	@RequestMapping(value="/treeCube")
	public AjaxResult treeCube(@RequestParam Integer cubeId){
		List<Map<String, Object>> ret = cubeService.treeCube(cubeId);
		if(ret.size() == 0){
			return AjaxResult.error("无数据");
		}
		return AjaxResult.success(ret);
	}
}
